﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Party.PartyComponents.CustomPartyComponent
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Party.PartyComponents
{
  public class CustomPartyComponent : PartyComponent
  {
    private const string StringId = "quest_party_template_1";
    [SaveableField(10)]
    private TextObject _name;
    [SaveableField(20)]
    private Settlement _homeSettlement;
    [SaveableField(30)]
    private Hero _owner;
    [SaveableField(40)]
    private float _customPartyBaseSpeed;
    [SaveableField(50)]
    private string _partyMountStringId;
    [SaveableField(60)]
    private string _partyHarnessStringId;
    [SaveableField(70)]
    public bool _avoidHostileActions;

    internal static void AutoGeneratedStaticCollectObjectsCustomPartyComponent(
      object o,
      List<object> collectedObjects)
    {
      ((PartyComponent) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._name);
      collectedObjects.Add((object) this._homeSettlement);
      collectedObjects.Add((object) this._owner);
    }

    internal static object AutoGeneratedGetMemberValue_avoidHostileActions(object o)
    {
      return (object) ((CustomPartyComponent) o)._avoidHostileActions;
    }

    internal static object AutoGeneratedGetMemberValue_name(object o)
    {
      return (object) ((CustomPartyComponent) o)._name;
    }

    internal static object AutoGeneratedGetMemberValue_homeSettlement(object o)
    {
      return (object) ((CustomPartyComponent) o)._homeSettlement;
    }

    internal static object AutoGeneratedGetMemberValue_owner(object o)
    {
      return (object) ((CustomPartyComponent) o)._owner;
    }

    internal static object AutoGeneratedGetMemberValue_customPartyBaseSpeed(object o)
    {
      return (object) ((CustomPartyComponent) o)._customPartyBaseSpeed;
    }

    internal static object AutoGeneratedGetMemberValue_partyMountStringId(object o)
    {
      return (object) ((CustomPartyComponent) o)._partyMountStringId;
    }

    internal static object AutoGeneratedGetMemberValue_partyHarnessStringId(object o)
    {
      return (object) ((CustomPartyComponent) o)._partyHarnessStringId;
    }

    public float CustomPartyBaseSpeed
    {
      get => this._customPartyBaseSpeed;
      set => this._customPartyBaseSpeed = value;
    }

    public override bool AvoidHostileActions => this._avoidHostileActions;

    public float BaseSpeed => this._customPartyBaseSpeed;

    public override Hero PartyOwner => this._owner;

    public override TextObject Name => this._name;

    public override Settlement HomeSettlement => this._homeSettlement;

    public static MobileParty CreateQuestParty(
      Vec2 position,
      float spawnRadius,
      Settlement homeSettlement,
      TextObject name,
      Clan clan,
      PartyTemplateObject partyTemplate,
      Hero owner,
      int troopLimit = 0,
      string partyMountStringId = "",
      string partyHarnessStringId = "",
      float customPartyBaseSpeed = 0.0f,
      bool avoidHostileActions = false)
    {
      return MobileParty.CreateParty("quest_party_template_1", (PartyComponent) new CustomPartyComponent(), (PartyComponent.OnPartyComponentCreatedDelegate) (mobileParty =>
      {
        (mobileParty.PartyComponent as CustomPartyComponent).InitializeQuestPartyProperties(mobileParty, position, spawnRadius, homeSettlement, name, partyTemplate, owner, troopLimit, partyMountStringId, partyHarnessStringId, customPartyBaseSpeed, avoidHostileActions);
        mobileParty.ActualClan = clan;
      }));
    }

    public static MobileParty CreateQuestParty(
      Vec2 position,
      float spawnRadius,
      Settlement homeSettlement,
      TextObject name,
      Clan clan,
      TroopRoster troopRoster,
      TroopRoster prisonerRoster,
      Hero owner,
      string partyMountStringId = "",
      string partyHarnessStringId = "",
      float customPartyBaseSpeed = 0.0f,
      bool avoidHostileActions = false)
    {
      return MobileParty.CreateParty("quest_party_template_1", (PartyComponent) new CustomPartyComponent(), (PartyComponent.OnPartyComponentCreatedDelegate) (mobileParty =>
      {
        (mobileParty.PartyComponent as CustomPartyComponent).InitializeQuestPartyProperties(mobileParty, position, spawnRadius, homeSettlement, name, troopRoster, prisonerRoster, owner, partyMountStringId, partyHarnessStringId, customPartyBaseSpeed, avoidHostileActions);
        mobileParty.ActualClan = clan;
      }));
    }

    private void InitializeQuestPartyProperties(
      MobileParty mobileParty,
      Vec2 position,
      float spawnRadius,
      Settlement homeSettlement,
      TextObject name,
      PartyTemplateObject partyTemplate,
      Hero owner,
      int troopLimit,
      string partyMountStringId,
      string partyHarnessStringId,
      float customPartyBaseSpeed,
      bool avoidHostileActions)
    {
      this._name = name;
      this._homeSettlement = homeSettlement;
      this._owner = owner;
      mobileParty.InitializeMobilePartyAroundPosition(partyTemplate, position, spawnRadius, troopNumberLimit: troopLimit);
      mobileParty.Party.SetVisualAsDirty();
      this._partyMountStringId = partyMountStringId;
      this._partyHarnessStringId = partyHarnessStringId;
      this.SetBaseSpeed(customPartyBaseSpeed);
      this._avoidHostileActions = avoidHostileActions;
    }

    private void InitializeQuestPartyProperties(
      MobileParty mobileParty,
      Vec2 position,
      float spawnRadius,
      Settlement homeSettlement,
      TextObject name,
      TroopRoster troopRoster,
      TroopRoster prisonerRoster,
      Hero owner,
      string partyMountStringId,
      string partyHarnessStringId,
      float customPartyBaseSpeed,
      bool avoidHostileActions)
    {
      this._name = name;
      this._homeSettlement = homeSettlement;
      this._owner = owner;
      mobileParty.InitializeMobilePartyAroundPosition(troopRoster, prisonerRoster, position, spawnRadius);
      mobileParty.Party.SetVisualAsDirty();
      this._partyMountStringId = partyMountStringId;
      this._partyHarnessStringId = partyHarnessStringId;
      this.SetBaseSpeed(customPartyBaseSpeed);
      this._avoidHostileActions = avoidHostileActions;
    }

    public void SetBaseSpeed(float speed)
    {
      this._customPartyBaseSpeed = speed;
      this.MobileParty?.UpdateVersionNo();
    }

    public override void GetMountAndHarnessVisualIdsForPartyIcon(
      PartyBase party,
      out string mountStringId,
      out string harnessStringId)
    {
      mountStringId = this._partyMountStringId;
      harnessStringId = this._partyHarnessStringId;
    }
  }
}
